package com.example;

import com.example.dao.BookDao;
import com.example.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //按照bean的id获取bean
        BookDao bookDao = (BookDao) ctx.getBean("bookDao");
        System.out.println(bookDao);

        //按类型获取bean
        BookService bookService = ctx.getBean(BookService.class);
        System.out.println(bookService);
        //如果注解@Component中没有给参数，即没有给bean起名称，默认是当前类名首字母小写
        BookService bookService1 = (BookService)ctx.getBean("bookServiceImpl");
        System.out.println(bookService1);
    }
}
